import { getUserContact } from '@/api/user'
import storage from '@/utils/storage'
import Dialog from '/wxcomponents/vant/dialog/dialog';
export function getContact({ viewId, viewType }) {
  return new Promise(async (resolve, reject) => {
    const { code, data: phoneNumber } = await getUserContact({ viewId, viewType })
    if (code === 200) {
      uni.makePhoneCall({
        phoneNumber
      })
      resolve()
    } else if (code === 208) {
      let messageFlag = storage.getStorage('info').messageFlag
      if (!messageFlag) {
        console.log(Dialog, 'Dialog')
        Dialog.confirm({
          title: '温馨提示',
          cancelButtonText: '去完善',
          closeOnClickOverlay: true,
          showCancelButton: true,
          cancelButtonColor: '#00B277',
          confirmButtonColor: '#00B277',
          confirmButtonText: '去邀请',
          message: '您当前已无剩余联系次数，\n请完善资料或邀请好友获取',
        })
        .then((e) => {
          console.log(e)
          uni.navigateTo({
            url: '/pages/invite/index'
          })
        }).catch(e => {
          if (e.action === 'cancel') {
            uni.navigateTo({
              url: '/pages/center/infomation/person'
            })
          }
        });
      } else {
        Dialog.alert({
          title: '温馨提示',
          cancelButtonColor: '#999999',
          confirmButtonColor: '#00B277',
          cancelButtonText: '再逛逛',
          showCancelButton: true,
          closeOnClickOverlay: true,
          confirmButtonText: '去邀请',
          message: '您当前已无剩余联系次数，\n邀请好友注册，可获取更多机会',
        }).then(() => {
          uni.navigateTo({
            url: '/pages/invite/index'
          })
          // on close
        }).catch(() => {
          
        });
      }
      reject()
    }
  })
}